from django.db import models


class Article(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='文章ID')
    title = models.CharField(max_length=100, verbose_name='文章标题')
    author = models.ForeignKey('account.User', related_name='articles', on_delete=models.CASCADE, verbose_name='作者')
    public = models.BooleanField(default=True, verbose_name='公开')
    classifies = models.ManyToManyField('account.Classify', related_name='articles', verbose_name='分类')
    tags = models.ManyToManyField('account.Tag', related_name='articles', verbose_name='标签')
    publish_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
    content = models.TextField(verbose_name='带HTML标签文章内容')
    text_content = models.TextField(verbose_name='纯文本内容')

    class Meta:
        db_table = 'article'


class Evaluate(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='评价表ID')
    article = models.OneToOneField('Article', related_name='evaluate', on_delete=models.CASCADE, verbose_name='文章ID')
    praise = models.PositiveIntegerField(verbose_name='赞')
    tread = models.PositiveIntegerField(verbose_name='踩')

    class Meta:
        db_table = 'evaluate'


class Comment(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='评论表ID')
    article = models.ForeignKey('Article', related_name='comments', on_delete=models.CASCADE, verbose_name='文章ID')
    user = models.ForeignKey("account.User", related_name='comments', on_delete=models.SET_NULL,
                             null=True, verbose_name='所属用户')
    content = models.TextField(verbose_name='评论内容')
    create_date = models.DateTimeField(auto_now_add=True, verbose_name='发布时间')
    is_child = models.BooleanField(default=False, verbose_name='是否为子评论')
    parent_id = models.ForeignKey('Comment', related_name='child_comments', on_delete=models.CASCADE,
                                  null=True, verbose_name='所属的父评论ID')
    reply_to = models.ForeignKey('account.User', related_name='comment_by_reply', on_delete=models.SET_NULL,
                                 null=True, verbose_name='回复的用户名')
    up_count = models.PositiveIntegerField(default=0, verbose_name='点赞数')

    class Meta:
        db_table = 'comment'



